'''
Created on Sep 6, 2012

@author: peng
'''
import subprocess


def run_command(command):
    p = subprocess.Popen(command, bufsize=2048, shell=True,
                         stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    p.wait()
    return p


def get_log_size():
    command = 'du -s /home/peng/test '
    command += "| awk 'BEGIN {SUM=0}{ SUM+=$1} END {print SUM}'"
    ret = run_command(command)
    lines = ret.stdout.readlines()
    return lines[-1].replace('\n', '')


if __name__ == '__main__':
    print get_log_size()
